<template>
    <div>
        <br><br><br><br><br><br><br><br><br>
        <el-row :gutter="20" justify="center" type="flex">
            <el-col :span="6">
                <template>
                    <el-select v-model="categoryToOthers" filterable placeholder="请选择要执行折扣的游戏类别">
                        <el-option
                            v-for="item in allGameCategory"
                            :key="item.id"
                            :label="item.classesName"
                            :value="item.id">
                        </el-option>
                    </el-select>
                </template>
            </el-col>
            <el-col :span="6">
                <el-input-number v-model="others.discount" 
                                placeholder="值0~1" 
                                :precision="2"
                                width="140px" 
                                :step="0.01" 
                                :min="0.01" 
                                :max="0.99">
                </el-input-number>
            </el-col>
            <el-col :span="6">
                <el-button type="success" @click="commitUpload">保存提交<i class="el-icon-upload el-icon--right"></i></el-button>
            </el-col>
        </el-row>
        
    </div>
</template>
<script>
import axios from 'axios';
export default {
    name:'discountManage',
    data() {
        return {
            others:{
                showPhoto1:'',
                showPhoto2:'',
                showPhoto3:'',
                teachPhoto:'',
                categoryId:'',
                discount:''
            },
            allGameCategory:[],
        };
    },
    mounted(){
        axios.get('/others/getSlideShow').then(
            response=>{
                this.others=response.data.data;
            }
        );
        axios.get('/game-category/getAll').then(
            response=>{
                this.allGameCategory=response.data.data;
                this.allGameCategory.unshift({
                                id:'',
                                classesName:'不设置打折游戏',
                            });
            }
        )
    },
    computed:{
        categoryToOthers:{
            get(){
                var categoryName='';
                this.allGameCategory.forEach((gc)=>{
                    if(gc.id===this.others.categoryId){
                        categoryName=gc.classesName;
                        return;
                    }
                })
                return categoryName;
            },
            set(value){
                this.others.categoryId=value;
            }
        }
    },
    methods:{
        commitUpload(){
            axios(
                {
                    method:'post',
                    url:'/others/updateOthers',
                    data:this.others
                }
            ).then(response=>{
                response;
                alert('修改成功');
            }) 
        }
    }
}
</script>
<style scoped>
 .el-row {
    margin-bottom: 20px;
  }
  .el-col {
    border-radius: 4px;
  }
  .bg-purple-dark {
    background: #99a9bf;
  }
  .bg-purple {
    background: #d3dce6;
  }
  .bg-purple-light {
    background: #e5e9f2;
  }
  .grid-content {
    border-radius: 4px;
    min-height: 36px;
  }
  .row-bg {
    padding: 10px 0;
    background-color: #f9fafc;
  }
</style>